﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using DataAccess.DataObject;
using System.Configuration;
using System.Security.Cryptography;

namespace EnmineKaitlin.admin
{
    public partial class login : Common.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string Password = "";
            using (MD5 md5Hash = MD5.Create())
            {
                Password = GetMd5Hash(md5Hash, txtPassword.Text);
            }            
            IList<OUser> lstUser =_BUser.Get(txtUserName.Text,Password);
            if (lstUser.Count > 0)
            {
                Session["username"] = txtUserName.Text;
                IList<OPermission> lstPermission = _BPermission.Get(lstUser[0].IDGroup);
                Session["permission"] = lstPermission;
                Session["fullname"] = lstUser[0].FullName;
                Session["user_id"] = lstUser[0].UserID;
                Response.Redirect("~/admin");
            }
            else {
                RegisterClientScriptBlock("NOTE", "<script>alert('"+ConfigurationManager.AppSettings["login_fail"].ToString()+"');</script>");
            }
        }
    }
}
